#ifndef _COMMON_H_
#define _COMMON_H_

namespace robot {
	static const int nspeeds = 11;

	struct SpeedInfo {
		double velocity;
		int energy_use;
	};

	extern SpeedInfo speeds[nspeeds];

	class Exception {
		const char* info;

		public:

		Exception(const char* p): info(p) {}
		operator const char*() { return info; }
	};

	template<class T> class BasicPoint {
		public:

		T x, y;

		BasicPoint(T ax, T ay): x(ax), y(ay) {}

		bool operator< (const BasicPoint<T>& p) const { return x < p.x || x == p.x && y < p.y; }
	};

	typedef BasicPoint<int> Point;

	class BasicSquare {
		protected:

		char c;

		public:

		BasicSquare(char ac = '.'): c(ac) {}

		operator const char() const { return c; }

		int GetMaxSpeed() const { return (c == '@') ? 4 : (nspeeds - 1); }
		int GetEnergyFactor() const { return (c == '@') ? 10 : 1; }
		int GetEnergyContribution() const { return (c == '%') ? 10 : 0; }

		bool IsEnterable() const { return c == '.' || c == '@' || c == '~' || c == '#' || c == '%'; }
		bool IsTransparent() const { return IsEnterable(); }
		bool IsDestructable() const { return !IsEnterable() || c == '#'; }
		bool IsKilling() const { return c == '~'; }
		bool IsRefuge() const { return c == '%'; }
	};

	double polar_angle(double y, double x);

	template<class T> inline T sqr(T x) { return x*x; }
}

#endif
